<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box1 {
            background-color: grey;
            width: 500px;
            height: 500px;
        }
        .box2 {
            background-color: orange;
            width: 100px;
            height: 100px;

            /*transition: all 0.5s;*/
            animation-name: test;
            animation-duration: 2s;
            animation-iteration-count: infinite;

            animation-direction: alternate-reverse;

            animation-play-state: running;

            animation-fill-mode: ;
        }

        .box1:hover .box2 {
            animation-play-state: paused;
        }
        /*.box1:hover .box2 {*/
        /*    margin-left: 400px;*/
        /*}*/

        @keyframes test {
            from {
                margin-left: 0;
            }
            to {
                margin-left: 400px;
            }
        }
    </style>
</head>
<body>
<div class="box1">
    <div class="box2">

    </div>
</div>
</body>
</html>